package segment

import "encoding/json"

// 词性
type Pos struct {
	Code       string `json:"code"` // 词性代码
	Name       string `json:"name"` // 词性名称
	Meaningful bool   `json:"meaningful"` // 是否有意义
}

func (p *Pos) Marshal() ([]byte, error) {
	return json.Marshal(p)
}

func (p *Pos) Unmarshal(data []byte) error {
	return json.Unmarshal(data, p)
}

func (p *Pos) String() string {
	j, _ := p.Marshal()
	return string(j)
}

func newPos(code, name string, meaningful bool) Pos {
	return Pos{
		Code:       code,
		Name:       name,
		Meaningful: meaningful,
	}
}

// 词性类名
// https://github.com/fxsjy/jieba
var POS map[string]Pos = map[string]Pos{
	"n":    newPos("n", "普通名词", true),
	"f":    newPos("f", "方位名词", true),
	"s":    newPos("s", "所处名词", true),
	"t":    newPos("t", "时间", true),
	"time": newPos("time", "时间", true),
	"TIME": newPos("TIME", "时间", true),
	"nr":   newPos("nr", "人名", true),
	"per":  newPos("per", "人名", true),
	"PER":  newPos("PER", "人名", true),
	"ns":   newPos("ns", "地名", true),
	"loc":  newPos("loc", "地名", true),
	"LOC":  newPos("LOC", "地名", true),
	"nt":   newPos("nt", "机构名", true),
	"org":  newPos("org", "机构名", true),
	"ORG":  newPos("ORG", "机构名", true),
	"nw":   newPos("nw", "作品名", true),
	"nz":   newPos("nz", "其他专名", true),
	"v":    newPos("v", "普通动词", true),
	"vd":   newPos("vd", "动副词", true),
	"vn":   newPos("vn", "名动词", true),
	"a":    newPos("a", "形容词", true),
	"ad":   newPos("ad", "副形容词", true),
	"an":   newPos("an", "名形容词", true),
	"d":    newPos("d", "副词", true),
	"m":    newPos("m", "数量词", true),
	"q":    newPos("q", "量词", true),
	"r":    newPos("r", "代词", true),
	"p":    newPos("p", "介词", false),
	"c":    newPos("c", "连词", false),
	"u":    newPos("u", "助词", false),
	"xc":   newPos("xc", "其他虚词", false),
	"w":    newPos("w", "标点符号", false),
}
